﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BartonExtension;

namespace Model.Images
{
    public class UploadImageEntity
    {
        public Int64 imageID { get; set; }
        public string ori_image_url { get; set; }
        public string tiny_thumb_image_url { get; set; }
        public string medium_thumb_image_url { get; set; }
        public string big_thumb_image_url { get; set; }

        public UploadImageEntity()
        {
            generateID();
        }

        public void generateID()
        {
            this.imageID = IDGenerator.GenerateID();
        }
        
        public void generateThumbs()
        {
            List<string> fragments = ori_image_url.Split('/').ToList();
            if (fragments.Count > 2)
            {
                string pathID = fragments[fragments.Count - 2];
                string filename = fragments.Last();

                big_thumb_image_url = "/userdata/thumbspool/{0}/{1}/big_{2}".FormatWith(pathID,this.imageID, filename);
                medium_thumb_image_url = "/userdata/thumbspool/{0}/{1}/medium_{2}".FormatWith(pathID, this.imageID, filename);
                tiny_thumb_image_url = "/userdata/thumbspool/{0}/{1}/small_{2}".FormatWith(pathID, this.imageID, filename);
            }
        }
    }
}